'use strict';

const Test = require('supertest/lib/test')

Test.prototype.ava = function(test, doc) {
  const status = test.title.match(/^\[([1-5][0-9]{2})\]/)
  if ( status ) {
    this.expect(parseInt(status[1]))
  }

  const code = test.title.match(/\<([0-9a-zA-Z_]+)\>/)
  if ( code ) {
    if ( code[1] === 'SUCCESS' ) {
      this.expect(/\"success\"\: true/)
    } else {
      this.expect(code[1])
    }
  }

  if ( doc ) {
    const title = test.title.match(/\]\s+(.*)/i)
    if ( title ) {
      this.set('X-Doc-Title', title[1])
    }
  }

  return this
}

const supertest = require('supertest')

const IS_REMOVE = process.env.REMOTE
const HOST = 'https://sz.yixiubao.cn'
const app = IS_REMOVE?HOST:require('../../../app').listen()

module.exports = supertest(app)

